package com.wdd.atcrowdfunding.manager.service.impl;

import com.wdd.atcrowdfunding.bean.Type;
import com.wdd.atcrowdfunding.manager.dao.TypeMapper;
import com.wdd.atcrowdfunding.manager.service.TypeService;
import com.wdd.atcrowdfunding.util.Page;
import com.wdd.atcrowdfunding.vo.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class TypeServiceImpl implements TypeService {

    @Autowired
    private TypeMapper typeMapper;

    @Override
    public List<Type> selectAll() {

        return typeMapper.selectByExample(null);
    }

    @Override
    public Type queryById(Integer id) {
        return typeMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateType(Type type) {
        return typeMapper.updateByPrimaryKey(type);
    }

    @Override
    public void insertType(Type type) {
        typeMapper.insert(type);
    }

    @Override
    public int deleteType(Integer id) {
        return typeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int deleteTypes(Data ds) {
        return typeMapper.deleteTypes(ds);
    }

    @Override
    public Page<Type> pageQuery(Map<String, Object> paramMap) {
        Page<Type> certPage = new Page<Type>((Integer)paramMap.get("pageno"),(Integer)paramMap.get("pagesize"));
        paramMap.put("startIndex", certPage.getStartIndex());
        List<Type> types = typeMapper.pageQuery(paramMap);
        // 获取数据的总条数
        int count = typeMapper.queryCount(paramMap);
        certPage.setDatas(types);
        certPage.setTotalsize(count);
        return certPage;
    }
}
